package org.chapter02;

import static org.junit.Assert.assertEquals;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.junit.Test;

/**
 * Unit test for simple App.
 */

public class LoginLogout {
                                          
	@Test
	public void LoginLogoutTest() {
		IniSecurityManagerFactory factory = new IniSecurityManagerFactory(
				"shiro-multi-realm.ini");
		SecurityManager manager = factory.getInstance();
		SecurityUtils.setSecurityManager(manager);
		Subject user = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken("zhang", "123");
		user.login(token);
		assertEquals(true, user.isAuthenticated());
		user.logout();
	}
}
